/*
 *	ME2 C++ SDK
 *	Copyright (c) 2010 _silencer
 *
 *	Permission is hereby granted, free of charge, to any person
 *	obtaining a copy of this software and associated documentation
 *	files (the "Software"), to deal in the Software without
 *	restriction, including without limitation the rights to use,
 *	copy, modify, merge, publish, distribute, sublicense, and/or sell
 *	copies of the Software, and to permit persons to whom the
 *	Software is furnished to do so, subject to the following
 *	conditions:
 *
 *	The above copyright notice and this permission notice shall be
 *	included in all copies or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *	OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef UNREAL_NAME_H
#define UNREAL_NAME_H

#include "unreal_core.h"
#include "unreal_templates.h"

namespace unreal
{
	#pragma pack(push)
	#pragma pack(1)

	/*
		Read only for now (should we be messing with it anyway?)
	 */
	class uname
	{
	public:

		struct uname_entry
		{
			unsigned int index;
			unsigned int flags;
			char string[64];
		};

		uname( unsigned int index = 0 )
			: index_( index )
		{
		}

		const char* operator*() const
		{
			return (*table_)[index_]->string;
		}

		const char* get_str() const
		{
			return (*table_)[index_]->string;
		}

		bool operator==( const uname& name ) const
		{
			return ( index_ == name.index_ );
		}

		bool operator!=( const uname& name ) const
		{
			return ( index_ != name.index_ );
		}

		unsigned int get_index() const
		{
			return index_;
		}

		unsigned int get_flags() const
		{
			return (*table_)[index_]->flags;
		}

		bool is_valid() const
		{
			return this && table_->is_valid( index_ ) && (*table_)[index_];
		}

		bool is_none() const
		{
			return ( index_ == 0 );
		}

		friend uname find_global_name( const std::string& name );

	private:

		static uarray<uname_entry*>* table_;
		unsigned int index_;
	};

	#pragma pack(pop)

	uname find_global_name( const std::string& name );
}

#endif
